

<!-- 砍价-好友打开 -->
<template>
	<view class="container">

		<view class="shareOpen-Container">
			<image class="bargainBg" :src="icon.bargainBg" mode="widthFix"></image>
			<image class="centerBg" :src="icon.centerBg" mode="widthFix"></image>
			<image class="logo" :src="icon.logo"></image>

			<view class="bargainTips">
				<view>
					好友【{{shareName}}】
				</view>
				<view>
				 	正在低价购买商品
				</view>
			</view>


			<!-- #ifdef H5 -->
			<view v-if="weixinFalg" class="launchApp-Container">
				<!-- v-pre -->
				<img :src="icon.goAppBargain" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;">
				<view class="wx_goAppBargain" style="z-index: 9999;">
					<wx-open-launch-app id="launch-btn" appid="wx3a03d02f5f83c054" :extinfo="paramBargainId">
						<script type="text/wxtag-template">
							<style>
								.btn {
									opacity: 0;
									width: 268px;
									height: 45px;
									border: 0;
									border-radius: 30px;
									-webkit-tap-highlight-color: rgba(0,0,0,0);
									-webkit-tap-highlight-color: transparent;
								}
							</style>
							<button class="btn">去芬尼湾APP帮我砍一刀</button>
						</script>
					</wx-open-launch-app>
				</view>
			</view>
			<image v-else class="h5_goAppBargain" :src="icon.goAppBargain" @click="normalBrowserLaunchApp()"></image>
			<!-- #endif -->
		</view>
	</view>
</template>

<script>
	import {
	    mapState,
	    mapMutations
	} from 'vuex';

	// #ifdef H5
	import wx from 'jweixin-module';
	// #endif

	export default {
		computed:{
			...mapState(['hasLogin', 'imgSite', 'downUrl']),
		},
		data() {
			return {
				icon: {
					bargainBg: "/pagesGoods/static/images/specialArea/bargainArea/bargainBg.png",
					centerBg: "/pagesGoods/static/images/specialArea/bargainArea/centerBg.png",
					logo: "/pagesGoods/static/images/specialArea/bargainArea/logo.png",
					goAppBargain: "/pagesGoods/static/images/specialArea/bargainArea/goAppBargain.png",
				},

				//微信浏览器
				weixinFalg: "",
				paramBargainId: "",
				shareName: "",
				goodsName: "",
				bargainId: ""
			};
		},
		onLoad: function(options) {

			this.shareName = options.shareName;
			this.goodsName = options.goodsName;
			this.bargainId = options.bargainId;

			// #ifdef H5
			//微信浏览器标识
			var ua = window.navigator.userAgent.toLowerCase();
			if (ua.match(/MicroMessenger/i) == 'micromessenger') {
				this.weixinFalg = true;
			} else {
				this.weixinFalg = false;
			}

			this.paramBargainId = "bargainId="+this.bargainId;


			var btn = document.getElementById('launch-btn');
			if(btn) {
				// btn.setAttribute('extinfo', "id="+e.id);

				let url = this.downUrl;
				btn.addEventListener('error', function (e) {
					uni.showToast({
						title: e.detail,
						icon: "none"
					});

					// setTimeout(function(){
					// 	window.location.href = url;
					// }, 5000);
				});
			}
			// #endif


			//获取签名
			// #ifdef H5

			let that = this;
			that.$api.globalUtil.requestAjax({
				url: '/PayApi/wxPaySignForApi',
				method: 'POST',
				data: {
					// webUrl: encodeURIComponent(window.location.href.split('#')[0])
					webUrl: window.location.href.split('#')[0]
				},
				success: function(res) {

					var appid = res.data.response.appid;
					var timestamp = res.data.response.timestamp;
					var nonceStr = res.data.response.nonceStr;
					var signature = res.data.response.signature;


					/**
					 * 配置信息
					 */
					wx.config({

						// debug: true,

						// 必填，微信appid
						appId: appid,

						// 必填，生成签名的时间戳
						timestamp: timestamp,

						// 必填，生成签名的随机串
						nonceStr: nonceStr,

						// 必填，签名，见附录1
						signature: signature,

						// 必填，需要使用的JS接口列表，所有JS接口列表见附录2
						jsApiList: ['scanQRCode'],

						// 可选，需要使用的开放标签列表，例如['wx-open-launch-app']
						openTagList: ['wx-open-launch-app']
					});

					wx.ready(function() {
						// console.log("准备就绪");
					});

					wx.error(function(res) {
						alert(res);
						uni.showToast({
							title: JSON.stringify(res),
							icon: "none"
						});
					});
				}
			});
			// #endif
		},
		methods: {

			//普通浏览器打开APP
			normalBrowserLaunchApp() {

				window.location.href = 'fnwqsg://bargainId='+this.bargainId;

				let url = this.downUrl;
				setTimeout(function(){
					window.location.href = url;
				}, 5000);
			},
		}
	};
</script>
<style lang="less">

	.shareOpen-Container {
		position: absolute;
		width: 100%;
		left: 0;

		.bargainBg {
			width: 100%;
		}

		.centerBg {
			position: absolute;
			top: 334rpx;
			left: 0;
			width: 100%;
		}

		.logo {
			position: absolute;
			top: 310rpx;
			left: 50%;
			margin-left: -60rpx;
			width: 119rpx;
			height: 119rpx;
		}

		.bargainTips {
			position: absolute;
			top: 494rpx;
			left: 50%;
			margin-left: -268rpx;
			width: 536rpx;
			text-align: center;
			font-size:36rpx;
			color: #AD211C;
		}
	}


	//拉起app
	.launchApp-Container {
		position: absolute;
		top: 966rpx;
		left: 50%;
		margin-left: -268rpx;
		width: 536rpx;
		height: 120rpx;

		.wx_goAppBargain {
			z-index: 1;
			position: absolute;
			top: 0;
			left: 0;
			width: 536rpx;
			height: 120rpx;
		}
	}


	//普通浏览器
	.h5_goAppBargain {
		position: absolute;
		top: 966rpx;
		left: 50%;
		margin-left: -268rpx;
		width: 536rpx;
		height: 120rpx;
	}
</style>



